Skip to content

feat(database): layerTest, a Database with no server for unit tests - #93

Merged
Makisuo merged 4 commits into
MapleTechLabs:mainfrom
artile:feat/test-layers
Nov 2, 2026
Merged

Makisuo merged 4 commits into
MapleTechLabs:mainfrom
artile:feat/test-layers

Conversation

@artile

@artile artile commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

No description provided.

@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 52 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ca6822e1-ab6d-4d1f-8fd4-1a278c9b2339
Commits

Reviewing files that changed from the base of the PR and between b57faf1 and 71e82cf.

Files selected for processing: 10
  • .changeset/database-test-layer.md
  • docs/README.md
  • docs/database.md
  • docs/reference.md
  • docs/testing.md
  • scripts/check-doc-examples.mjs
  • src/database.ts
  • src/database/test-layer.test-d.ts
  • src/database/test-layer.test.ts
  • src/database/test-layer.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Makisuo and others added 2 commits November 2, 2026 16:29
…nd afterCommit

SqlClient.make now requires a driver name. Tests the fake on sqliteDialect
(? placeholders, integer booleans, BEGIN/COMMIT), d1Dialect (no transactions)
and Db.afterCommit (runs after COMMIT, never after ROLLBACK).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Makisuo

Makisuo commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Merge-readiness pass (71e82cf):

  • Merged main into the branch (it was based on c5fa679). The merge had no textual conflicts.
  • Fixed the build on Effect 4.0.6. SqlClient.make now requires a driver name, so the fake client passes driver: "effect-orm-test". Without it the typecheck failed.
  • Added tests for the dialects that are new on main. sqliteDialect sends ? placeholders, decodes integer booleans and records BEGIN/SELECT/COMMIT. d1Dialect fails a transaction with TransactionUnsupported and sends nothing.
  • Added a test for afterCommit (feat(database): afterCommit runs work after the outermost COMMIT #100): Db.afterCommit hooks run after the recorded COMMIT and never after a ROLLBACK.
  • Updated the TestDatabaseOptions.dialect doc and docs/testing.md to list all four dialects and mention afterCommit and D1.

Verified locally:

  • bun run build and bun run typecheck are clean.
  • bun run test against live ClickHouse 26.8 with PGlite and node:sqlite, including fuzz at FUZZ_SCALE=0.3, passed 74 files and 1441 tests. The doc citation, export catalog and doc example checks also pass, with 27 doc example files including the new one.
  • bun run test:package passes the tarball and CommonJS consumer checks.

CI run 41472238736 started without needing approval. If it fails only on the known fuzz flakes, they are fixed separately in #131: ClickHouse/Postgres division by zero in generated fixtures …, or compiled row codec retains generated values.

@maple-review-bot

maple-review-bot Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Maple review

🟡 Confidence 6/10 · needs attention. Held at 6 because a correctness warning is open.
1 warning −1 · tests partial −1 · risk medium

Adds Db.layerTest, a Database with no server for unit tests: a fake SqlClient records every statement and answers with queued rows or a driver SqlError, so compile, decode, tenant scope and transactions run unchanged. The mechanism is sound and covered for Postgres, ClickHouse, SQLite and D1.

  • layerTest provides Database | TestDatabase over a fake SqlClient connection
  • TestDatabase records statements and queues rows or driver SqlErrors
  • TestReply, TestStatement and the layer are exported from /database

Findings

🟠 Warning · F1 · SET TRANSACTION takes the reply queued for the transaction body's query

correctness · src/database/test-layer.ts:87-88

With postgresDialect, Db.transaction(body, { isolationLevel }) first runs SET TRANSACTION through Database.execute (src/database/database.ts:392), which is the prepared path, so it pops the next queued reply. The body's query then gets respond or no rows, and the test sees [] instead of what it queued.

Skip the queue in `answer` for the transaction-settings statement (SQL starting with `SET TRANSACTION`), the way `control` already does for BEGIN and COMMIT.
🤖 Prompt to fix this finding with an AI agent
Findings from an automated review of commit 71e82cfebd2dff94a936d495c46af349beecb035. Verify each one against the current code before changing anything, fix only those that still apply, and keep each fix to the lines it names.

---

F1 · Warning · correctness · src/database/test-layer.ts:87-88
`SET TRANSACTION` takes the reply queued for the transaction body's query
With `postgresDialect`, `Db.transaction(body, { isolationLevel })` first runs `SET TRANSACTION` through `Database.execute` (`src/database/database.ts:392`), which is the prepared path, so it pops the next queued reply. The body's query then gets `respond` or no rows, and the test sees `[]` instead of what it queued.
Suggested fix: Skip the queue in `answer` for the transaction-settings statement (SQL starting with `SET TRANSACTION`), the way `control` already does for BEGIN and COMMIT.

71e82cf · What was checked, coverage and telemetry details are on the Maple / review check. Reply "won't fix" to dismiss a finding, or mention @maple-review-bot to ask about one.

@maple-review-bot maple-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 inline note from Maple's review. The score and summary are in the review comment above.

replies.slice(1),
]),
(next) => {
const reply = next ?? respond(statement)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

SET TRANSACTION takes the reply queued for the transaction body's query

F1 · Warning · correctness

With postgresDialect, Db.transaction(body, { isolationLevel }) first runs SET TRANSACTION through Database.execute (src/database/database.ts:392), which is the prepared path, so it pops the next queued reply. The body's query then gets respond or no rows, and the test sees [] instead of what it queued.

Skip the queue in `answer` for the transaction-settings statement (SQL starting with `SET TRANSACTION`), the way `control` already does for BEGIN and COMMIT.
🤖 Prompt to fix with an AI agent
In `src/database/test-layer.ts:87-88`: `SET TRANSACTION` takes the reply queued for the transaction body's query.

With `postgresDialect`, `Db.transaction(body, { isolationLevel })` first runs `SET TRANSACTION` through `Database.execute` (`src/database/database.ts:392`), which is the prepared path, so it pops the next queued reply. The body's query then gets `respond` or no rows, and the test sees `[]` instead of what it queued.

Suggested fix: Skip the queue in `answer` for the transaction-settings statement (SQL starting with `SET TRANSACTION`), the way `control` already does for BEGIN and COMMIT.

Verify the problem exists at that location before changing it, and keep the fix to those lines.

@Makisuo
Makisuo merged commit d09a941 into MapleTechLabs:main Nov 2, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants